home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / auto-save.el.z / auto-save.el
Encoding:
Text File  |  1998-05-21  |  20.2 KB  |  542 lines

  1. ;; -*- Emacs-Lisp -*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;
  4. ;; File:          auto-save.el
  5. ;; Version:       $Revision: 1.25 $
  6. ;; RCS:           
  7. ;; Description:   Safer autosaving with support for efs and /tmp.
  8. ;;                This version of auto-save is designed to work with efs,
  9. ;;                instead of ange-ftp.
  10. ;; Author:        Sebastian Kremer <sk@thp.uni-koeln.de>,
  11. ;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. (defconst auto-save-version (substring "$Revision: 1.25 $" 11 -2)
  15.   "Version number of auto-save.")
  16.  
  17. ;;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de>
  18.  
  19. ;;; This program is free software; you can redistribute it and/or modify
  20. ;;; it under the terms of the GNU General Public License as published by
  21. ;;; the Free Software Foundation; either version 1, or (at your option)
  22. ;;; any later version.
  23.  
  24. ;;; This program is distributed in the hope that it will be useful,
  25. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. ;;; GNU General Public License for more details.
  28.  
  29. ;;; You should have received a copy of the GNU General Public License
  30. ;;; along with this program; if not, write to the Free Software
  31. ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32.  
  33. ;;;; OVERVIEW ==========================================================
  34.  
  35. ;;; Combines autosaving for efs (to a local or remote directory)
  36. ;;; with the ability to do autosaves to a fixed directory on a local
  37. ;;; disk, in case NFS is slow.  The auto-save file used for
  38. ;;;     /usr/foo/bar/baz.txt
  39. ;;; will be
  40. ;;;     AUTOSAVE/#\!usr\!foo\!bar\!baz.txt#
  41. ;;; assuming AUTOSAVE is the non-nil value of the variable
  42. ;;; `auto-save-directory'.
  43.  
  44. ;;; Takes care that autosave files for non-file-buffers (e.g. *mail*)
  45. ;;; from two simultaneous Emacses don't collide.
  46.  
  47. ;;; Autosaves even if the current directory is not writable.
  48.  
  49. ;;; Can limit autosave names to 14 characters using a hash function,
  50. ;;; see `auto-save-hash-p'.
  51.  
  52. ;;; See `auto-save-directory' and `make-auto-save-file-name' and
  53. ;;; references therein for complete documentation.
  54.  
  55. ;;; Meta-x recover-all-files will effectively do recover-file on all
  56. ;;; files whose autosave file is newer (one of the benefits of having
  57. ;;; all autosave files in the same place).
  58.  
  59. ;;;; INSTALLATION ======================================================
  60.  
  61. ;;; Put this file into your load-path and the following in your ~/.emacs:
  62.  
  63. ;;; If you want to autosave in the fixed directory /tmp/USER-autosave/
  64. ;;; (setq auto-save-directory
  65. ;;;       (concat "/tmp/" (user-login-name) "-autosave/"))
  66.  
  67. ;;; If you don't want to save in /tmp (e.g., because it is swap
  68. ;;; mounted) but rather in ~/autosave/
  69. ;;;   (setq auto-save-directory (expand-file-name "~/autosave/"))
  70.  
  71. ;;; If you want to save each file in its own directory (the default)
  72. ;;;   (setq auto-save-directory nil)
  73. ;;; You still can take advantage of autosaving efs remote files
  74. ;;; in a fixed local directory, `auto-save-directory-fallback' will
  75. ;;; be used.
  76.  
  77. ;;; If you want to use 14 character hashed autosave filenames
  78. ;;;   (setq auto-save-hash-p t)
  79.  
  80. ;;; Finally, put this line after the others in your ~/.emacs:
  81. ;;;   (require 'auto-save)
  82.  
  83.  
  84. ;;;; ACKNOWLEDGEMENT ===================================================
  85.  
  86. ;;; This code is loosely derived from autosave-in-tmp.el by Jamie
  87. ;;; Zawinski <jwz@netscape.com> (the version I had was last modified 22
  88. ;;; dec 90 jwz) and code submitted to ange-ftp-lovers on Sun, 5 Apr
  89. ;;; 92 23:20:47 EDT by drw@BOURBAKI.MIT.EDU (Dale R. Worley).
  90. ;;; auto-save.el tries to cover the functionality of those two
  91. ;;; packages.
  92.  
  93. ;;; Valuable comments and help from Dale Worley, Andy Norman, Jamie
  94. ;;; Zawinski and Sandy Rutherford are gratefully acknowledged.
  95.  
  96. ;;;; PROVISION ========================================================
  97.  
  98. (provide 'auto-save)
  99.  
  100. ;;;; CUSTOMIZATION =====================================================
  101.  
  102. (defgroup auto-save nil
  103.   "Autosaving with support for efs and /tmp."
  104.   :group 'data)
  105.  
  106. (put 'auto-save-interval 'custom-type 'integer)
  107. (put 'auto-save-interval 'factory-value '(300))
  108. (custom-add-to-group 'auto-save 'auto-save-interval 'custom-variable)
  109.  
  110. (defcustom auto-save-directory nil
  111.  
  112.   ;;; Don't make this user-variable-p, it should be set in .emacs and
  113.   ;;; left at that.  In particular, it should remain constant across
  114.   ;;; several Emacs session to make recover-all-files work.
  115.  
  116.   "If non-nil, fixed directory for autosaving: all autosave files go
  117. there.  If this directory does not yet exist at load time, it is
  118. created and its mode is set to 0700 so that nobody else can read your
  119. autosave files.
  120.  
  121. If nil, each autosave files goes into the same directory as its
  122. corresponding visited file.
  123.  
  124. A non-nil `auto-save-directory' could be on a local disk such as in
  125. /tmp, then auto-saves will always be fast, even if NFS or the
  126. automounter is slow.  In the usual case of /tmp being locally mounted,
  127. note that if you run emacs on two different machines, they will not
  128. see each other's auto-save files.
  129.  
  130. The value \(expand-file-name \"~/autosave/\"\) might be better if /tmp
  131. is mounted from swap (possible in SunOS, type `df /tmp' to find out)
  132. and thus vanishes after a reboot, or if your system is particularly
  133. thorough when cleaning up /tmp, clearing even non-empty subdirectories.
  134.  
  135. It should never be an efs remote filename because that would
  136. defeat `efs-auto-save-remotely'.
  137.  
  138. Unless you set `auto-save-hash-p', you shouldn't set this to a
  139. directory in a filesystem that does not support long filenames, since
  140. a file named
  141.  
  142.     /home/sk/lib/emacs/lisp/auto-save.el
  143.  
  144. will have a longish filename like
  145.  
  146.     AUTO-SAVE-DIRECTORY/#\\!home\\!sk\\!lib\\!emacs\\!lisp\\!auto-save.el#
  147.  
  148. as auto save file.
  149.  
  150. See also variables `auto-save-directory-fallback',
  151. `efs-auto-save' and `efs-auto-save-remotely'."
  152.   :type '(choice (const :tag "Same as file" nil)
  153.          directory)
  154.   :group 'auto-save)
  155.  
  156.  
  157. (defcustom auto-save-hash-p nil
  158.   "If non-nil, hashed autosave names of length 14 are used.
  159. This is to avoid autosave filenames longer than 14 characters.
  160. The directory used is `auto-save-hash-directory' regardless of
  161. `auto-save-directory'.
  162. Hashing defeats `recover-all-files', you have to recover files
  163. individually by doing `recover-file'."
  164.   :type 'boolean
  165.   :group 'auto-save)
  166.  
  167. ;;; This defvar is in efs.el now, but doesn't hurt to give it here as
  168. ;;; well so that loading first auto-save.el does not abort.
  169. (or (boundp 'efs-auto-save) (defvar efs-auto-save 0))
  170. (or (boundp 'efs-auto-save-remotely) (defvar efs-auto-save-remotely nil))
  171.  
  172. (defcustom auto-save-offer-delete nil
  173.   "*If non-nil, `recover-all-files' offers to delete autosave files
  174. that are out of date or were dismissed for recovering.
  175. Special value 'always deletes those files silently."
  176.   :type '(choice (const :tag "on" t)
  177.          (const :tag "off" nil)
  178.          (const :tag "Delete silently" always))
  179.   :group 'auto-save)
  180.  
  181. ;;;; end of customization
  182.  
  183.  
  184. ;;; Preparations to be done at load time
  185.  
  186. (defvar auto-save-directory-fallback (expand-file-name "~/autosave/")
  187.   ;; not user-variable-p, see above
  188.   "Directory used for local autosaving of remote files if
  189. both `auto-save-directory' and `efs-auto-save-remotely' are nil.
  190. Also used if a working directory to be used for autosaving is not writable.
  191. This *must* always be the name of directory that exists or can be
  192. created by you, never nil.")
  193.  
  194. (defvar auto-save-hash-directory
  195.   (expand-file-name "hash/" (or auto-save-directory
  196.                 auto-save-directory-fallback))
  197.   "If non-nil, directory used for hashed autosave filenames.")
  198.  
  199. (defun auto-save-check-directory (var)
  200.   (let ((dir (symbol-value var)))
  201.     (if (null dir)
  202.     nil
  203.       ;; Expand and store back into the variable
  204.       (set var (setq dir (expand-file-name dir)))
  205.       ;; Make sure directory exists
  206.       (if (file-directory-p dir)
  207.       nil
  208.     ;; Else we create and chmod 0700 the directory
  209.     (setq dir (directory-file-name dir)) ; some systems need this
  210.     (if (fboundp 'make-directory)    ; V19 or tree dired
  211.         (make-directory dir)
  212.       (call-process "mkdir" nil nil nil dir))
  213.     (set-file-modes dir (* 7 8 8))))))
  214.  
  215. (mapcar (function auto-save-check-directory)
  216.     '(auto-save-directory auto-save-directory-fallback))
  217.  
  218. (and auto-save-hash-p
  219.      (auto-save-check-directory 'auto-save-hash-directory))
  220.  
  221.  
  222. ;;; Computing an autosave name for a file and vice versa
  223.  
  224. (defun make-auto-save-file-name ();; redefines files.el
  225.   ;; auto-save-file-name-p need not be redefined.
  226.  
  227.   "Return file name to use for auto-saves of current buffer.
  228. Does not consider `auto-save-visited-file-name'; that is checked
  229. before calling this function.
  230.  
  231. Offers to autosave all files in the same `auto-save-directory'.  All
  232. autosave files can then be recovered at once with function
  233. `recover-all-files'.
  234.  
  235. Takes care to make autosave files for files accessed through efs
  236. be local files if variable `efs-auto-save-remotely' is nil.
  237.  
  238. Takes care of slashes in buffer names to prevent autosave errors.
  239.  
  240. Takes care that autosave files for buffers not visiting any file (such
  241. as `*mail*') from two simultaneous Emacses don't collide by prepending
  242. the Emacs pid.
  243.  
  244. Uses 14 character autosave names if `auto-save-hash-p' is true.
  245.  
  246. Autosaves even if the current directory is not writable, using
  247. directory `auto-save-directory-fallback'.
  248.  
  249. You can redefine this for customization (he he :-).
  250. See also function `auto-save-file-name-p'."
  251.  
  252.   ;; We have to be very careful about not signalling an error in this
  253.   ;; function since files.el does not provide for this (e.g. find-file
  254.   ;; would fail for each new file).
  255.  
  256.   (condition-case error-data
  257.       (let* ((file-name (or (and (boundp 'buffer-file-truename)
  258.                  buffer-file-truename
  259.                  ;; Make sure that the file name is expanded.
  260.                  (expand-file-name buffer-file-name))
  261.                 (and buffer-file-name
  262.                  (expand-file-name buffer-file-name))))
  263.          ;; So autosavename looks like #%...#, roughly as with the
  264.          ;; old make-auto-save-file-name function.  The
  265.          ;; make-temp-name inserts the pid of this Emacs: this
  266.          ;; avoids autosaving from two Emacses into the same file.
  267.          ;; It cannot be recovered automatically then because in
  268.          ;; the next Emacs session (the one after the crash) the
  269.          ;; pid will be different, but file-less buffers like
  270.          ;; *mail* must be recovered manually anyway.
  271.  
  272.          ;; jwz: putting the emacs PID in the auto-save file name is bad
  273.          ;; news, because that defeats auto-save-recovery of *mail*
  274.          ;; buffers -- the (sensible) code in sendmail.el calls
  275.          ;; (make-auto-save-file-name) to determine whether there is
  276.          ;; unsent, auto-saved mail to recover. If that mail came from a
  277.          ;; previous emacs process (far and away the most likely case)
  278.          ;; then this can never succeed as the pid differs.
  279. ;;         (name-prefix (if file-name nil (make-temp-name "#%")))
  280.          (name-prefix (if file-name nil "#%"))
  281.  
  282.          (save-name (or file-name
  283.                 ;; Prevent autosave errors.  Buffername
  284.                 ;; (to become non-dir part of filename) will
  285.                 ;; be unslashified twice.  Don't care.
  286.                 (auto-save-unslashify-name (buffer-name))))
  287.          (remote-p (and (stringp file-name)
  288.                 (fboundp 'efs-ftp-path)
  289.                 (efs-ftp-path file-name))))
  290.     ;; Return the appropriate auto save file name:
  291.     (expand-file-name;; a buffername needs this, a filename not
  292.      (if remote-p
  293.          (if efs-auto-save-remotely
  294.          (auto-save-name-in-same-directory save-name)
  295.            ;; We have to use the `fixed-directory' now since the
  296.            ;; `same-directory' would be remote.
  297.            ;; It will use the fallback if needed.
  298.            (auto-save-name-in-fixed-directory save-name))
  299.        ;; Else it is a local file (or a buffer without a file, hence
  300.            ;; the name-prefix).
  301.        ;; Hashed files always go into the special hash dir, never
  302.        ;; in the same directory, to make recognizing reliable.
  303.        (if (or auto-save-directory auto-save-hash-p)
  304.            (auto-save-name-in-fixed-directory save-name name-prefix)
  305.          (auto-save-name-in-same-directory save-name name-prefix)))))
  306.     
  307.     ;; If any error occurs in the above code, return what the old
  308.     ;; version of this function would have done.  It is not ok to
  309.     ;; return nil, e.g., when after-find-file tests
  310.     ;; file-newer-than-file-p, nil would bomb.
  311.  
  312.     (error (progn
  313.          (message "make-auto-save-file-name %s" error-data)
  314.          (sit-for 2)
  315.          (if buffer-file-name
  316.          (concat (file-name-directory buffer-file-name)
  317.              "#"
  318.              (file-name-nondirectory buffer-file-name)
  319.              "#")
  320.            (expand-file-name (concat "#%" (buffer-name) "#")))))))
  321.  
  322. (defun auto-save-original-name (savename)
  323.   "Reverse of `make-auto-save-file-name'.
  324. Returns nil if SAVENAME was not associated with a file (e.g., it came
  325. from an autosaved `*mail*' buffer) or does not appear to be an
  326. autosave file at all.
  327. Hashed files are not understood, see `auto-save-hash-p'."
  328.   (let ((basename (file-name-nondirectory savename))
  329.     (savedir (file-name-directory savename)))
  330.     (cond ((or (not (auto-save-file-name-p basename))
  331.            (string-match "^#%" basename))
  332.        nil)
  333.       ;; now we know it looks like #...# thus substring is safe to use
  334.       ((or (equal savedir auto-save-directory) ; 2nd arg may be nil
  335.            (equal savedir auto-save-directory-fallback))
  336.        ;; it is of the `-fixed-directory' type
  337.        (auto-save-slashify-name (substring basename 1 -1)))
  338.       (t
  339.        ;; else it is of `-same-directory' type
  340.        (concat savedir (substring basename 1 -1))))))
  341.  
  342. (defun auto-save-name-in-fixed-directory (filename &optional prefix)
  343.   ;; Unslashify and enclose the whole FILENAME in `#' to make an auto
  344.   ;; save file in the auto-save-directory, or if that is nil, in
  345.   ;; auto-save-directory-fallback (which must be the name of an
  346.   ;; existing directory).  If the results would be too long for 14
  347.   ;; character filenames, and `auto-save-hash-p' is set, hash FILENAME
  348.   ;; into a shorter name.
  349.   ;; Optional PREFIX is string to use instead of "#" to prefix name.
  350.   (let ((base-name (concat (or prefix "#")
  351.                (auto-save-unslashify-name filename)
  352.                "#")))
  353.     (if (and auto-save-hash-p
  354.          auto-save-hash-directory
  355.          (> (length base-name) 14))
  356.     (expand-file-name (auto-save-cyclic-hash-14 filename)
  357.               auto-save-hash-directory)
  358.       (expand-file-name base-name
  359.             (or auto-save-directory
  360.                 auto-save-directory-fallback)))))
  361.  
  362. (defun auto-save-name-in-same-directory (filename &optional prefix)
  363.   ;; Enclose the non-directory part of FILENAME in `#' to make an auto
  364.   ;; save file in the same directory as FILENAME.  But if this
  365.   ;; directory is not writable, use auto-save-directory-fallback.
  366.   ;; FILENAME is assumed to be in non-directory form (no trailing slash).
  367.   ;; It may be a name without a directory part (pesumably it really
  368.   ;; comes from a buffer name then), the fallback is used then.
  369.   ;; Optional PREFIX is string to use instead of "#" to prefix name.
  370.   (let ((directory (file-name-directory filename)))
  371.     (or (null directory)
  372.     (file-writable-p directory)
  373.     (setq directory auto-save-directory-fallback))
  374.     (concat directory            ; (concat nil) is ""
  375.         (or prefix "#")
  376.         (file-name-nondirectory filename)
  377.         "#")))
  378.  
  379. (defun auto-save-unslashify-name (s)
  380.   ;;  "Quote any slashes in string S by replacing them with the two
  381.   ;;characters `\\!'.
  382.   ;;Also, replace any backslash by double backslash, to make it one-to-one."
  383.   (let ((limit 0))
  384.     (while (string-match "[/\\]" s limit)
  385.       (setq s (concat (substring s 0 (match-beginning 0))
  386.               (if (string= (substring s
  387.                           (match-beginning 0)
  388.                           (match-end 0))
  389.                    "/")
  390.               "\\!"
  391.             "\\\\")
  392.               (substring s (match-end 0))))
  393.       (setq limit (1+ (match-end 0)))))
  394.   s)
  395.  
  396. (defun auto-save-slashify-name (s)
  397.   ;;"Reverse of `auto-save-unslashify-name'."
  398.   (let (pos)
  399.     (while (setq pos (string-match "\\\\[\\!]" s pos))
  400.       (setq s (concat (substring s 0 pos)
  401.               (if (eq ?! (aref s (1+ pos))) "/" "\\")
  402.               (substring s (+ pos 2)))
  403.         pos (1+ pos))))
  404.   s)
  405.  
  406.  
  407. ;;; Hashing for autosave names
  408.  
  409. ;;; Hashing function contributed by Andy Norman <ange@hplb.hpl.hp.com>
  410. ;;; based upon C code from pot@fly.cnuce.cnr.IT (Francesco Potorti`).
  411.  
  412. (defun auto-save-cyclic-hash-14 (s)
  413.   ;;   "Hash string S into a string of length 14.
  414.   ;; A 7-bytes cyclic code for burst correction is calculated on a
  415.   ;; byte-by-byte basis. The polynomial used is D^7 + D^6 + D^3 +1.
  416.   ;; The resulting string consists of hexadecimal digits [0-9a-f].
  417.   ;; In particular, it contains no slash, so it can be used as autosave name."
  418.   (let ((crc (make-string 7 0))
  419.     result)
  420.     (mapcar
  421.      (function
  422.       (lambda (new)
  423.     (setq new (+ new (aref crc 6)))
  424.     (aset crc 6 (+ (aref crc 5) new))
  425.     (aset crc 5 (aref crc 4))
  426.     (aset crc 4 (aref crc 3))
  427.     (aset crc 3 (+ (aref crc 2) new))
  428.     (aset crc 2 (aref crc 1))
  429.     (aset crc 1 (aref crc 0))
  430.     (aset crc 0 new)))
  431.      s)
  432.     (setq result (format "%02x%02x%02x%02x%02x%02x%02x"
  433.              (aref crc 0)
  434.              (aref crc 1)
  435.              (aref crc 2)
  436.              (aref crc 3)
  437.              (aref crc 4)
  438.              (aref crc 5)
  439.              (aref crc 6)))
  440.     result))
  441.  
  442. ;; This leaves two characters that could be used to wrap it in `#' or
  443. ;; make two filenames from it: one for autosaving, and another for a
  444. ;; file containing the name of the autosaved filed, to make hashing
  445. ;; reversible.
  446. (defun auto-save-cyclic-hash-12 (s)
  447.   "Outputs the 12-characters ascii hex representation of a 6-bytes
  448. cyclic code for burst correction calculated on STRING on a
  449. byte-by-byte basis. The used polynomial is D^6 + D^5 + D^4 + D^3 +1."
  450.   (let ((crc (make-string 6 0)))
  451.     (mapcar
  452.      (function
  453.       (lambda (new)
  454.         (setq new (+ new (aref crc 5)))
  455.         (aset crc 5 (+ (aref crc 4) new))
  456.         (aset crc 4 (+ (aref crc 3) new))
  457.         (aset crc 3 (+ (aref crc 2) new))
  458.         (aset crc 2 (aref crc 1))
  459.         (aset crc 1 (aref crc 0))
  460.         (aset crc 0 new)))
  461.      s)
  462.     (format "%02x%02x%02x%02x%02x%02x"
  463.             (aref crc 0)
  464.             (aref crc 1)
  465.             (aref crc 2)
  466.             (aref crc 3)
  467.             (aref crc 4)
  468.             (aref crc 5))))
  469.  
  470.  
  471.  
  472. ;;; Recovering files
  473.  
  474. (defun recover-all-files (&optional silent)
  475.   "Do recover-file for all autosave files which are current.
  476. Only works if you have a non-nil `auto-save-directory'.
  477.  
  478. Optional prefix argument SILENT means to be silent about non-current
  479. autosave files.  This is useful if invoked automatically at Emacs
  480. startup.
  481.  
  482. If `auto-save-offer-delete' is t, this function will offer to delete
  483. old or rejected autosave files.
  484.  
  485. Hashed files (see `auto-save-hash-p') are not understood, use
  486. `recover-file' to recover them individually."
  487.   (interactive "P")
  488.   (let ((savefiles (directory-files auto-save-directory t "^#"))
  489.     afile                ; the auto save file
  490.     file                ; its original file
  491.     (total 0)            ; # of files offered to recover
  492.     (count 0))            ; # of files actually recovered
  493.     (or (equal auto-save-directory auto-save-directory-fallback)
  494.     (setq savefiles
  495.           (append savefiles
  496.               (directory-files auto-save-directory-fallback t "^#"))))
  497.     (while savefiles
  498.       (setq afile (car savefiles)
  499.         file (auto-save-original-name afile)
  500.         savefiles (cdr savefiles))
  501.       (cond ((and file (not (file-newer-than-file-p afile file)))
  502.          (message "autosave file \"%s\" is not current." afile)
  503.          (sit-for 2))
  504.         (t
  505.          (setq total (1+ total))
  506.          (with-output-to-temp-buffer "*Directory*"
  507.            (apply 'call-process "ls" nil standard-output nil
  508.               "-l" afile (if file (list file))))
  509.          (if (yes-or-no-p (format "Recover %s from auto save file? "
  510.                       (or file "non-file buffer")))
  511.          (let* ((obuf (current-buffer))
  512.             (buf (set-buffer
  513.                   (if file
  514.                   (find-file-noselect file t)
  515.                 (generate-new-buffer "*recovered*"))))
  516.             (buffer-read-only nil))
  517.            (erase-buffer)
  518.            (insert-file-contents afile nil)
  519.            (condition-case ()
  520.                (after-find-file nil)
  521.              (error nil))
  522.            (setq buffer-auto-save-file-name nil)
  523.            (setq count (1+ count))
  524.            (message "\
  525. Auto-save off in buffer \"%s\" till you do M-x auto-save-mode."
  526.                 (buffer-name))
  527.            (set-buffer obuf)
  528.            (sit-for 1))
  529.            ;; If not used for recovering, offer to delete
  530.            ;; autosave file
  531.            (and auto-save-offer-delete
  532.             (or (eq 'always auto-save-offer-delete)
  533.             (yes-or-no-p
  534.              (format "Delete autosave file for `%s'? " file)))
  535.             (delete-file afile))))))
  536.     (if (zerop total)
  537.     (or silent (message "Nothing to recover."))
  538.       (message "%d/%d file%s recovered." count total (if (= count 1) "" "s"))))
  539.   (if (get-buffer "*Directory*") (kill-buffer "*Directory*")))
  540.  
  541. ;;; end of auto-save.el
  542.